package com.example.boot.http.provider.controller;

import com.example.boot.http.provider.bean.User;
import com.example.boot.http.provider.common.Result;
import com.example.boot.http.provider.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/json")
public class JSONController {

    private final UserService userService;

    @PostMapping("/add")
    public Result<User> add(@RequestBody User user) {
        User data = userService.add(user);
        Result<User> result = new Result<>();
        result.success(data);
        return result;
    }

    @GetMapping("/get/{id}")
    public Result<User> get(@PathVariable("id") Integer id) {
        User user = userService.get(id);
        Result<User> result = new Result<>();
        result.success(user);
        return result;
    }
}
